﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BO;
using System.Collections;
using System.Reflection;
using BrightIdeasSoftware;
namespace UI.Core
{
    public partial class DataLookupForm<T> : Form where T:IEnumerable,IBusinessList,new()
    {
        public DataLookupForm()
        {
            InitializeComponent();
            
        }
        private IList _ReturnObjects;
        public IList ReturnObjects
        {
            get { return _ReturnObjects; }
        }
       
      
        protected override void OnLoad(EventArgs e)
        {
          
            base.OnLoad(e);
            cols = new List<OLVColumn>();
            var tName=typeof(T).Name;
            var tableName=tName.Remove(tName.Length-4,4);
            switch (tableName)
            {
                case DataBaseObject.Tables.SysUser:
                    GetSysUser();
                    break;
                case DataBaseObject.Tables.SysRole:
                    GetSysRole();
                    break;
            }
          
        }
        List<OLVColumn> cols;
        void GetSysUser()
        {
            cols.Add(new OLVColumn("用户名",DataBaseObject.Columns.SysUser_UserName));

            grid.Columns.AddRange(cols.ToArray());
            grid.Objects = ListFactory<T>.GetList("IsInactive=0");
        }
        void GetSysRole()
        {
            cols.Add(new OLVColumn("角色名", DataBaseObject.Columns.SysRole_RoleName));
            cols.Add(new OLVColumn("角色描述", DataBaseObject.Columns.SysRole_RoleDescription));

            grid.Columns.AddRange(cols.ToArray());
            grid.Objects = ListFactory<T>.GetList("IsInactive=0");
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            var objs=grid.SelectedObjects;
            if (objs.Count == 0)
                return;
            _ReturnObjects = objs;
            this.DialogResult = System.Windows.Forms.DialogResult.OK;

        }


       

    }
}
